<?php

/**
 * Kysat Bootstrap
 *
 * @category   Kysat
 * @package    Kysat_Bootstrap
 * @copyright  Copyright (c) 2008 Joseph Bratton
 */

// Setup error reporting level
error_reporting(E_ALL|E_STRICT);

// Setup the include path
set_include_path('.' . PATH_SEPARATOR . '../protected/Zend/incubator/library'
                . PATH_SEPARATOR . '../protected/Zend/library'
                . PATH_SEPARATOR . get_include_path());
require_once "Zend/Loader.php";

// Register framework's class autoloader
Zend_Loader::registerAutoload();

// Setup the front controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->setBaseUrl('');
$frontController->setDefaultModule('core');
$frontController->throwExceptions(true);
$frontController->addModuleDirectory('../protected/KySat/modules');

// Load the site's config file and add it to the registry
$siteConfig = new Zend_Config_Ini('../protected/KySat/config/settings.ini', 'site');
Zend_Registry::set('siteConfig', $siteConfig);

// Set timezone using setting from the settings.ini config
date_default_timezone_set($siteConfig->timezone);

// Setup the database connection using settings from settings.ini
$dbConfig = new Zend_Config_Ini('../protected/KySat/config/settings.ini', 'database');
$db = Zend_Db::factory($dbConfig->adapter, $dbConfig->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);

// Setup the Router
$router = new Zend_Controller_Router_Rewrite();
// Add routes from settings.ini config
$routesConfig = new Zend_Config_Ini('../protected/KySat/config/settings.ini', 'routes');
$router->addConfig($routesConfig);
// Set the frontController's router
$frontController->setRouter($router);

// Get rid of global $router and $routesConfig variables
unset($routesConfig);
unset($router);

// Create the layout using the theme specified in the settings.ini config
$layout = Zend_Layout::startMvc(array(
    'layoutPath'    => './themes/' . $siteConfig->theme->name,
    'layout'        => 'page',
));

// Get the view and add the proper helper paths
$view = $layout->getView();
$view->addHelperPath(array(
    '../protected/Zend/incubator/library/Zend/View/Helper',
    '../protected/Zend/library/Zend/View/Helper',
));
$view->addHelperPath('../protected/KySat/library/Kysat/View/Helper', 'Kysat_View_Helper_');

// Set the site's title using setting from the settings.ini config
$view->headTitle($siteConfig->title);

// Unset global variables
unset($siteConfig);
unset($layout);
unset($view);

// run!
$frontController->dispatch();
